package com.ray.com.ray.demo.impl;

import com.ray.com.ray.demo.BookManager;
import com.ray.com.ray.demo.aop.LogPrinter;
import com.ray.com.ray.demo.bean.Book;
import com.ray.com.ray.demo.exception.BizException;
import com.ray.com.ray.demo.exception.ServiceException;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.MessageFormat;

/**
 * Created by alisports-it06 on 2016/12/22.
 */
@Service("bookManager")
public class BookManagerImpl implements BookManager {

    @LogPrinter(moniterCode = "A002",desc = "addBook desc2")
    public int addBook(String bookName, BigDecimal bookPrice) throws Exception {
        int i = 1;
        i++;
        Thread.sleep(3000);
        System.out.println("do addBook ing");
        //throw new BizException(111, "aaaa");
        //throw new ServiceException(222, "bbb");
        return i;
    }

    @LogPrinter(moniterCode = "A001",desc = "removeBook desc")
    public void removeBook(Integer bookId) {
        System.out.println("=== remove book, id = " + bookId);
    }

    @LogPrinter(moniterCode = "A003",desc = "removeBook desc")
    public Book addBook(Book book) {
        book.setBookName("fdfsdf");
        book.setPrice(1315.21);
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return book;
    }

}
